<?php
/**
 * 新入职的用户
 */
apf_require_class('APF_Controller');
apf_require_class('Bll_Flow_User');
class Api_NewUsersController extends APF_Controller {
    public function handle_request() {
        $bll = new Bll_Flow_User();
        //返回正在办理的
        $_where = array(
             "is_entry"=>0
        );
        $job_list =$parent_list= $userdata= array();
        $list = $bll->get_user_by_where($_where);
        if(!empty($list)){
            $oahr_bll = new Bll_Hr_OutInterface();
            foreach($list as $val){
                if(empty($val['office_mail'])){
                    continue;
                }
                $job_list[$val['entry_id']] = $val['job_id'];
                $parent_list[$val['entry_id']] = $val['parent_id'];

                $userdata[$val['entry_id']] = array(
                        'entry_id'=>$val['entry_id'],
                        'user_id'=>0,
                        'name'=>$val['real_name'],
                        'code'=>$val['user_code'],
                        'email'=>$val['office_mail'],
                        'mobile'=>$val['cellphone'],
                        'enter_date'=>$val['re_entry_date'],
                        'indue_date'=>0,
                        'dimission_date'=>0,
                        'english_name'=>$val['english_name'],
                        'department_name'=>'',
                        'job_name'=>'',
                        'city_name'=>'',
                        );
            }
            if(!empty($job_list)){
                $parent_uids = array_values($parent_list);
                $parent_data = $oahr_bll->get_user_by_ids($parent_uids,0);
                $job_ids = array_values($job_list);
                $job_data = $oahr_bll->get_job_dep_infos($job_ids);
                foreach ($job_list as $entry_id=> $job_id){
                    $userdata[$entry_id]['department_name'] = $job_data[$job_id]['department_name'];
                    $userdata[$entry_id]['job_name'] = $job_data[$job_id]['job_name'];
                    $userdata[$entry_id]['city_name']= $job_data[$job_id]['city_name'];
                }
                foreach($parent_list as $entry_id=>$parent_id){
                    $userdata[$entry_id]['superior'] = array(
                            'user_id'=>$parent_id,
                            'email'=>$parent_data[$parent_id]['email'],
                            'name'=>$parent_data[$parent_id]['name'],
                            'code'=>$parent_data[$parent_id]['code'],
                            );
                }
                $userdata = array_slice($userdata, 0,500);//重置索引
            }
        }
        echo json_encode($userdata);
        exit;
    }
}